<?php	namespace Admin\Model;
use Hdphp\Model\Model;
class GoodsList extends Model
{
	protected $table = 'goodslist';
	public $validate = array(
		//验证规则参数
		//1.表单name名称 2.规则 3.提示信息 4.验证的条件 5.验证时机
		array('glnumber','required','请填写库存',3,3),
		array('inventory','required','请填写货号',3,3),
	);	
	public function store($gid)
	{	//执行自动验证
		if(!$this->create()) return false;
		$combine = Q('post.spec');
		//没有选择货品规格不余怒提交
		foreach ($combine as $k => $v) {
			if(empty($v)){
				$this->error = '请选择货品规格';return false;
			}
		}
		//将其转换为字符串
		$combine = implode(',', $combine);
		//所要添加的数据组合
		$data = array(
			'combine'=>$combine,
			'glnumber'=>Q('post.glnumber'),
			'inventory'=>Q('post.inventory'),
			'goods_gid'=>$gid
		);
		//执行添加	
		$this->add($data);		
		return true;				
	}
	/**
	 * 编辑
	 */
	public function edit($glid)
	{	//自动验证
		if(!$this->create())   return false;
		//执行编辑
		$this->where("glid={$glid}")->save();
		return true;
	}
}
